package com.sunrise.xdoc.interceptor;

import com.sunrise.xdoc.exception.XCoffeeServiceException;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The Class ExceptionsInterceptor.
 *
 * @author Nguyen Duc Dung
 * @since 5/18/13 11:14 AM
 */
public class ExceptionsInterceptor implements MethodInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(ExceptionsInterceptor.class);

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        try {
            return invocation.proceed();
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            throw new XCoffeeServiceException(ex);
        }
    }
}
